﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demo
{
    class Program
    {
        static void Main(string[] args)
        {   
            Test4();
            Test5();
            Test6();
            Test7();
       
        }
        static void Test6() 
        {
            int [] arr = { 100, 50, 30, 90 };
            int temp;
            for (int i = 0; i < arr.Length; i++)
            {
                for (int j = 0; j < arr.Length-1-i; j++)
                {
                    if (arr[j+1]>arr[j])
                    {
                        temp=arr[j + 1];
                        arr[j + 1] = arr[j];
                        arr[j] = temp;
                    }
                  
                }
            }
            for (int i = 0; i < arr.Length; i++)
            {
                Console.WriteLine(arr[i]+" ");
            }

        }
        static void Test5() 
        {
            double sum = 0;
            double avg ;
            double[] arr = { 80.5, 90.2, 97.8, 93 };
            foreach (double c in arr)
            {
                sum =sum+c ;

            }avg = sum / arr.Length;
            Console.WriteLine("总成绩为{0},平均成绩为{1}",sum,avg);
        }

        static void Test4() 
        {
            Console.WriteLine("请输入一行字符串");
            string str = Console.ReadLine();
            int IsWhiteSpace = 0;
            int IsLetter = 0;
            int IsDigit = 0;
            int IsPunctuation = 0;
            foreach (char c in str)
            {
                if (char.IsWhiteSpace(c))
                {
                    IsWhiteSpace++;
                }
                if (char.IsLetter(c))
                {
                    IsLetter++;
                }
                if (char.IsDigit(c))
                {
                    IsDigit++;
                }
                if (char.IsPunctuation(c))
                {
                    IsPunctuation++;
                }
            }
            Console.WriteLine("英文字母的个数为{0}、数字的个数为{1}、空格的个数为{2},符号的个数为{3}",IsLetter,IsDigit,IsWhiteSpace,IsPunctuation);

        }



        static void Test7() 
        {
            int[] arr = { 20, 30, 40, 50 ,50};
            Console.WriteLine("请输入要查找的元素");
            int num = int.Parse(Console.ReadLine());
            int temp = -1;
            for (int i = 0; i < arr.Length; i++)
            {

                if (arr[i] == num)
                {
                    temp = i;
                }
           
                
            }
            if (temp == -1)
            {
                Console.WriteLine("找不到该元素");
            }
            else { 
                Console.WriteLine("在数组中出现的位置{0}", temp+1);
            }
            


        }

        static void Test() 
        {
        string[] arr = new string[5];
        arr[0] = "20";
        arr[1] = "25";
        arr[2] = "30";
        arr[3] = "40";
        arr[4] = "60";

        for (int i = 0; i < arr.GetLength(0); i++)
        {

            if (i % 2 == 0)
            {
                Console.WriteLine(arr[i]);

            }
            
        }
       
        }

    }
}
